/**
 *
 * Copyright (c) 2012 NCS Corporation.
 *
 * Author: tangb
 * Created Date: Jun 1, 2012
 * 
 * 	version					author					remark
 * 	1.0						tangb				
 */
package com.ocgs.base.core.exception;

import com.ocgs.base.core.constant.BaseConstants;
import com.ocgs.base.util.PropertyUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * This is a base exception for all exceptions extends it under the MPA Project
 */
@SuppressWarnings("serial")
public class BaseException extends Exception {

	private static final Log log = LogFactory.getLog(BaseException.class);

	private String systemName;
	private String errorCode;
	private String message;

	public BaseException(String systemName, String errorPropertyKey, String message, Throwable cause) {
		super(message, cause);
		this.errorCode = getErrorCode(errorPropertyKey);
	}

	public BaseException(String systemName, String errorPropertyKey, Throwable cause) {
		super("BaseException", cause);
		this.errorCode = getErrorCode(errorPropertyKey);
		this.systemName = systemName;
	}

	public BaseException(String systemName, String errorPropertyKey) {
		this.errorCode = getErrorCode(errorPropertyKey);
		this.systemName = systemName;
	}

	public BaseException(String message) {
		super(message);
		this.message = message;
	}

	public BaseException(Throwable th) {
		super(th);
	}

	public BaseException(String mgs, Throwable th) {
		super(mgs, th);
	}

	public String getErrorCode(String propKey) {
		String errorCode = null;
		try {
			return PropertyUtil.getPropertyValue(BaseConstants.ERROR_CODE, propKey);
		} catch (Exception ex) {
			log.error("PropertyUtil get " + BaseConstants.ERROR_CODE + " " + propKey + " failure!", ex);
		}
		return errorCode;
	}

	public String getSystemName() {
		return systemName;
	}

	public void setSystemName(String systemName) {
		this.systemName = systemName;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
